home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / tchk21ex.zip / DEMOMOUS.C < prev    next >
C/C++ Source or Header  |  1989-06-06  |  11KB  |  302 lines

  1. /* TCHK 2.1 - Howard Kapustein's Turbo C library        6-6-89      */
  2. /* Copyright (C) 1988,1989 Howard Kapustein.  All rights reserved.  */
  3.  
  4. /* demolite.c  - used for testing TCHK mouse functions */
  5.  
  6. #include <howard.h>
  7. #include <mousehk.h>
  8. #include <video.h>
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <keyboard.h>
  12. #include <keycode.h>
  13. #include <dos.h>
  14.  
  15. /* Global variables */
  16. boolean ishidden, restrict = FALSE;
  17. int left, top, right, bottom;
  18.  
  19. /* function prototypes */
  20. void main();
  21. void Setup(void);
  22. void TestCoord(void);
  23. void RestrictCoord(void);
  24. void TestCursor(void);
  25. void Bye(void);
  26.  
  27. void main()
  28. {
  29.     Setup();
  30.     TestCoord();
  31.  
  32.     TestCursor();
  33.  
  34.     Bye();
  35. }
  36.  
  37.  
  38. void Setup(void)
  39. {
  40.     extern int _mouse2;
  41.     extern boolean ishidden;    /* is Mouse cursor hidden */
  42.  
  43.     if (!ismouse()) {           /* check for mouse */
  44.         printf("This demo requires a mouse\n");
  45.         exit(0);
  46.     }
  47.     cursor_off();
  48.     MCursorOn();                /* ismouse() sets internal mouse cursor variable to -1, we want it on */
  49.     ishidden = FALSE;
  50.     cls();
  51. }
  52.  
  53.  
  54. void TestCoord(void)
  55. {
  56.     extern int _mouse2, _mouse3, _mouse4;
  57.     extern boolean ishidden, restrict;
  58.     int x,y, status, key;
  59.     char savescreen[scrbuff(1,1,80,24)];
  60.     boolean done;
  61.  
  62.     gotohv(0,0);
  63.     printf("Button pressed at: \n");
  64.     printf("Mickeys from last: \n");
  65.     gotohv(60,0);
  66.     printf("Current: ");
  67.     gotohv(0,3);
  68.     printf("Press left button to end\n");
  69.     printf("Press right button to display mouse coordinates\n");
  70.     gotohv(0,6);
  71.     printf("Press left/right arrow to change horizontal mickey/pixel ratio\n");
  72.     printf("Press up/down arrow to change vertical mickey/pixel ratio\n");
  73.     gotohv(0,9);
  74.     printf("Press C to hide cursor\n");
  75.     printf("Press R to restrict mouse range\n");
  76.     printf("Press ALT-R to reset the mouse driver\n");
  77.     printf("Press ESC to abort demo\n");
  78.  
  79.     MCursorText(FALSE,0x00FF,0x1F00);
  80.     status = MButtonStatus();           /* clear button status */
  81.     if (status & LBPRESSED) {
  82.         MButtonPress(LEFTBUTTON);
  83.         MButtonRelease(LEFTBUTTON);
  84.     }
  85.     if (status & RBPRESSED) {
  86.         MButtonPress(RIGHTBUTTON);
  87.         MButtonRelease(RIGHTBUTTON);
  88.     }
  89.  
  90.     for (done = FALSE; !done;) {
  91.         status = MButtonStatus();
  92.         x = _mouse3;    y = _mouse4;
  93.         delay(100);                     /* needed to insure cursor is displayed on screen      */
  94.                                         /* don't believe me? comment out this function and see */
  95.                                         /* See note below for more details                     */
  96.         if ((key = inkeyc(FALSE)) != 0) {
  97.             switch (key) {
  98.                 case LEFTARROW: { MGetSensitivity();
  99.                                   _mouse2--;                    /* beware of underflow */
  100.                                   MSetRatio(_mouse2,_mouse3);
  101.                                   break; }
  102.                 case RIGHTARROW:{ MGetSensitivity();
  103.                                   _mouse2++;                    /* beware of overflow */
  104.                                   MSetRatio(_mouse2,_mouse3);
  105.                                   break; }
  106.                 case DOWNARROW: { MGetSensitivity();
  107.                                   _mouse3--;                    /* beware of underflow */
  108.                                   MSetRatio(_mouse2,_mouse3);
  109.                                   break; }
  110.                 case UPARROW:   { MGetSensitivity();
  111.                                   _mouse3++;                    /* beware of overflow */
  112.                                   MSetRatio(_mouse2,_mouse3);
  113.                                   break; }
  114.                 case 'C': { ishidden = !ishidden;
  115.                             ishidden ? MCursorOff() : MCursorOn();
  116.                             gotohv(0,9);
  117.                             printf(ishidden ? "Press C to show cursor" :
  118.                                               "Press C to hide cursor");
  119.                             break; }
  120.                 case 'R': { restrict = !restrict;
  121.                             if (restrict) {
  122.                                 gettext(1,1,80,24,savescreen);
  123.                                 RestrictCoord();
  124.                                 puttext(1,1,80,24,savescreen);
  125.                                 gotohv(60,1);
  126.                                 printf("(%3d,%3d) (%3d,%3d)",left/8,top/8,right/8,bottom/8);
  127.                                 gotohv(0,10);
  128.                                 printf("Press R to unrestrict mouse range\n");
  129.                             } else {
  130.                                 MCursorRangex(0,79*8);  /* each character is 8x8 pixels */
  131.                                 MCursorRangey(0,24*8);
  132.                                 gotohv(60,1);
  133.                                 printf("                   ");
  134.                                 gotohv(0,10);
  135.                                 printf("Press R to restrict mouse range  \n");
  136.                             }
  137.                             break; }
  138.                 case ALT_R: { MouseReset();
  139.                               MCursorText(FALSE,0x00FF,0x1F00);
  140.                               if (!ishidden)
  141.                                   MCursorOn();
  142.                               break; }
  143.                 case ESC: cursor_on();  exit(1);
  144.             }
  145.         }
  146.         gotohv(69,0);
  147.         printf("(%3d,%3d)",x/8,y/8);
  148.         if (status & RBPRESSED) {
  149.             MButtonPress(RIGHTBUTTON);
  150.             gotohv(20,0);
  151.             printf("(%4d,%4d)",_mouse3/8,_mouse4/8);
  152.             MMickeysMovedx();
  153.             gotohv(20,1);
  154.             printf("(%4d,%4d)  ",_mouse3,_mouse4);
  155.         }
  156.         if ((status & LBPRESSED) && (MButtonRelease(LEFTBUTTON) != 0)) {
  157.             /* left button pressed AND released */
  158.             MButtonPress(LEFTBUTTON);   /* clear Left Button Presses */
  159.             done = TRUE;
  160.             break;
  161.         }
  162.     }
  163. }
  164.  
  165.  
  166. void RestrictCoord(void)
  167. {
  168.     extern int left,top,right,bottom;
  169.     int status;
  170.  
  171.     cls();
  172.     printf("We're about to restrict the mouse coordinates\n");
  173.     printf("\nMove the mouse to the upper left corner of the boundary\n");
  174.     printf("    and press the right button\n");
  175.  
  176.     if (MButtonStatus() & RBPRESSED) {  /* clear button status */
  177.         MButtonPress(RIGHTBUTTON);
  178.         MButtonRelease(RIGHTBUTTON);
  179.     }
  180.     do {
  181.         status = MButtonStatus();
  182.         if (status & RBPRESSED) {
  183.             MButtonPress(RIGHTBUTTON);
  184.             left = _mouse3;
  185.             top = _mouse4;
  186.         }
  187.         if ((status & RBPRESSED) && (MButtonRelease(RIGHTBUTTON)!=0)) {
  188.             MButtonRelease(RIGHTBUTTON);    /* clear Right Button Presses */
  189.             break;
  190.         }
  191.     } while (TRUE);
  192.  
  193.     gotohv(0,5);
  194.     printf("\nMove the mouse to the lower right corner of the boundary\n");
  195.     printf("    and press the right button\n");
  196.  
  197.     if (MButtonStatus() & RBPRESSED) {  /* clear button status */
  198.         MButtonPress(RIGHTBUTTON);
  199.         MButtonRelease(RIGHTBUTTON);
  200.     }
  201.     do {
  202.         status = MButtonStatus();
  203.         if (status & RBPRESSED) {
  204.             MButtonPress(RIGHTBUTTON);
  205.             right = _mouse3;
  206.             bottom = _mouse4;
  207.         }
  208.         if ((status & RBPRESSED) && (MButtonRelease(RIGHTBUTTON)!=0)) {
  209.             MButtonRelease(RIGHTBUTTON);    /* clear Right Button Presses */
  210.             break;
  211.         }
  212.     } while (TRUE);
  213.  
  214.     MCursorRangex(left,right);          /* restrict cursor range */
  215.     MCursorRangey(top,bottom);
  216.  
  217.     MButtonPress(LEFTBUTTON);           /* clear internal mouse counters */
  218.     MButtonRelease(LEFTBUTTON);
  219.     MMickeysMovedx();
  220. }
  221.  
  222.  
  223. void TestCursor(void)
  224. {
  225.     extern unsigned int _Bitmap_StandardCursor[],
  226.                         _Bitmap_UpArrow[],
  227.                         _Bitmap_LeftArrow[],
  228.                         _Bitmap_CheckMark[],
  229.                         _Bitmap_PointingHand[],
  230.                         _Bitmap_DiagonalCross[],
  231.                         _Bi